package com.itic.mall.mobile.project;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.system.project.proexpress.persistence.model.ProjectExpress;
import com.itic.mall.system.project.proexpress.persistence.model.ProjectExpressExample;
import com.itic.mall.system.project.proexpress.persistence.model.ProjectExpressExample.Criteria;
import com.itic.mall.system.project.proexpress.service.ProjectExpressService;



@Controller
@RequestMapping(value="/mobile/project/express")
public class ProjectExpressInterface extends BaseMobileInterface{
	@Autowired
	private ProjectExpressService projectExpressService;
	
	@RequestMapping("list")
	@ResponseBody
	public Map<String,Object> projectExpress(HttpServletResponse response){
		Map<String, Object> resultMap = new HashMap<>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			List<Map<String, Object>> listMap = new ArrayList<>();
			ProjectExpressExample example = new ProjectExpressExample();
			Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			List<ProjectExpress> projectExpresses = this.projectExpressService.list(example);
			for(ProjectExpress express : projectExpresses) {
				Map<String, Object> dataMap = new HashMap<>();
				dataMap.put("id", express.getId());
				dataMap.put("name", express.getExpressCompanyNo());
				listMap.add(dataMap);
			}
			resultMap.put(DATA, listMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("ProjectExpressInterface", "projectExpress", e.toString(), "快递公司列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
}
